{extend name="public:index"/} {block name="title"}{:sysconf('title')}{/block} {block name="content"}
<section class="dingdanbox">
    <div class="top">
        <p class="p1">
            <a href="javascript:history.back(-1)"></a>
        </p>
        <p class="p2">填写订单</p>
        <p class="p3"></p>
    </div>
    <div style="height:2rem;"></div>
    <div class="ddbox">
        <p class="p1"></p>
        {if condition="$address"}
        <p class="p2"><b>{$address['name']}  {$address['mobile']}</b>
            <span>{$address['province']}{$address['city']}{$address['area']}{$address['info']}</span></p>
        {else/}
        <p class="p2" style="line-height:2rem;">点击添加地址</p>
        {/if}
        <p class="p3"></p>
    </div>
    <div class="shopmain">
        <ul class="shopul">
            {foreach name="list.goods" item="vo"}
            <li>
                <div class="center">
                    <a href="{:url('Goods/show',['id'=>$vo['goods_id']])}"><img src="{$vo['goods_img_url']}" alt=""></a>
                </div>
                <div class="right">
                    <b><a href="{:url('Goods/show',['id'=>$vo['goods_id']])}">{$vo['goods_title']}</a></b>
                    <p class="p1"><i>￥{$vo['goods_sell_price']}</i><em>X{$vo['goods_count']}</em></p>
                </div>
            </li>
            {/foreach}
        </ul>
        <!--<div class="xuanbox">
				<div class="xuan xuan2"><p class="p1">支付方式</p>
				<select name="payType" class="zhifufu">
					<option value="0">余额</option>
					<option value="1">微信</option>
				</select></div>
		    </div>-->
        <!-- <div class="xuanbox">
				<div class="xuan xuan2">
					<p class="p1">优惠券</p>
					<select name="coupon" class="zhifufu" onchange="saveSum(this.value)">
						<option value="">请选择</option>
						{foreach name="coupon" item="vo"}
						<option value="{$vo['coupon_money']}" data-id="{$vo['id']}">满{$vo['coupon_astrict']}减{$vo['coupon_money']}</option>
						{/foreach}
					</select>
				</div>
		    </div> -->
        <div class="xuanbox1">
            <div class="xuan xuan1">
                <p class="p1">商品金额</p>
                <p class="p2">￥{$list['sum']}</p>
            </div>
            <div class="xuan">
                <p class="p1">运费<em><!--（总重：0.4kg）--></em></p>
                <p class="p2">+￥{$cost|default="0"}</p>
                <p class="p3"></p>
            </div>
        </div>
    </div>
    <div class="jiesuan1">
        <div class="left">
            <p>实付款：￥<em id="orderSum">{$list['sum']+$cost}</em>元</p>
        </div>
        <div class="right"><input type="button" id="addOrder" value="提交订单"></div>
    </div>
</section>
<script type="text/javascript">
    function saveSum(coupon) {
        var oldSum = "{$list['sum']+$cost}";
        if (coupon != '') {
            var nowSum = oldSum - coupon;
            $("#orderSum").html(nowSum);
        } else {
            $("#orderSum").html(oldSum);
        }

    }
    $('.dingdanbox .ddbox').click(function() {
        window.location.href = "{:url('User/address')}";
    });
    $("#addOrder").click(function() {
        var addressId = "{$address['id']}";
        var cost = "{$cost}";
        var sum = "{$list['sum']}";
        var cartId = "{$cartId}";
        var couponId = $("select[name=coupon]").find("option:selected").data("id");
        if (addressId == '') {
            layer.msg('请选择或添加收货地址');
            return;
        }
        // var payType = $("select[name=payType]").val();
        var couponMoney = $("select[name=coupon]").val();
        $.ajax({
            url: "{:url('Order/add')}",
            type: "POST",
            data: {
                'addressId': addressId,
                'cost': cost,
                'sum': sum,
                'cartId': cartId,
                'couponMoney': couponMoney,
                'couponId': couponId
            },
            dataType: "JSON",
            success: function(data) {
                if (data.code == 0) {
                    window.location.href = "{:url('Pay/index')}?orderNo=" + data.data;
                } else {
                    layer.msg(data.msg, {
                        'icon': 5
                    });
                }
            },
            error: function() {
                layer.msg("网络延迟，发送失败", {
                    icon: 5
                });
            }
        });
    });
</script>
{/block}